package bb.lanxing.lib.devices.sgsettingentity.manager;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import com.google.gson.Gson;
import com.google.gson.JsonParseException;

import bb.lanxing.lib.devices.sgsettingentity.gearprofile.GearProfileSettings;
import bb.lanxing.lib.devices.sgsettingentity.setting.CommonSettings;
import bb.lanxing.lib.devices.sgsettingentity.userprofile.UserProfileSettings;
import kotlin.jvm.internal.Intrinsics;

public final class SGSettingsHelper {
    public final CommonSettings createCommonSettingsFromFile(String str) {
        try {
            Gson gson = new Gson();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(str)));
            StringBuilder sb = new StringBuilder();
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine != null) {
                    sb.append(readLine);
                } else {
                    String sb2 = sb.toString();
                    Intrinsics.checkNotNullExpressionValue(sb2, "stringBuilder.toString()");
                    CommonSettings fromJson = gson.fromJson(sb2, CommonSettings.class);
                    return fromJson;
                }
            }
        } catch (JsonParseException | IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public final CommonSettings createCommonSettingsFromString(String str) {
        try {
            Gson gson = new Gson();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(str)));
            StringBuilder sb = new StringBuilder();
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine != null) {
                    sb.append(readLine);
                } else {
                    String sb2 = sb.toString();
                    Intrinsics.checkNotNullExpressionValue(sb2, "stringBuilder.toString()");
                    CommonSettings fromJson = gson.fromJson(sb2, CommonSettings.class);
                    return fromJson;
                }
            }
        } catch (JsonParseException | IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public final UserProfileSettings createUserProfileSettingsFromFile(String str) {
        try {
            Gson gson = new Gson();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(str)));
            StringBuilder sb = new StringBuilder();
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine != null) {
                    sb.append(readLine);
                } else {
                    String sb2 = sb.toString();
                    Intrinsics.checkNotNullExpressionValue(sb2, "stringBuilder.toString()");
                    UserProfileSettings fromJson = gson.fromJson(sb2, UserProfileSettings.class);
                    return fromJson;
                }
            }
        } catch (JsonParseException | IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public final GearProfileSettings createGearProfileSettingsFromFile(String str) {
        try {
            Gson gson = new Gson();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(str)));
            StringBuilder sb = new StringBuilder();
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine != null) {
                    sb.append(readLine);
                } else {
                    String sb2 = sb.toString();
                    Intrinsics.checkNotNullExpressionValue(sb2, "stringBuilder.toString()");
                    GearProfileSettings fromJson = gson.fromJson(sb2, GearProfileSettings.class);
                    return fromJson;
                }
            }
        } catch (JsonParseException | IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public final String toString(CommonSettings commonSettings) {
        return new Gson().toJson(commonSettings);
    }

    public final String toString(UserProfileSettings userProfileSettings) {
        return new Gson().toJson(userProfileSettings);
    }

    public final String toString(GearProfileSettings gearProfileSettings) {
        return new Gson().toJson(gearProfileSettings);
    }
}
